﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Edge.Common;
using Edge.Common.Mail;
using Edge.Common.Services;
using Edge.Common.Utils;
using Shop.Business.Domain.Catalog;
using Shop.Business.Domain.Customers;
using Shop.Web.AppCode;
using SortDirection=Edge.Common.SortDirection;

namespace Shop.Web
{
    public partial class _Default : ShopBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           if (!IsPostBack)
           {
               PreDataBind();
           }
            ProductGroupFilter filter = new ProductGroupFilter();
            filter.InStock = true;
            FetchOptions fetchOptions = new FetchOptions(0,24,SortDirection.Descending,"Relevance");
            ctrlCatalog.DataSource = Locator.GetService<IProductGroupManager>().Find(fetchOptions,filter);

//            gridCustomers.DataSource = Locator.GetService<ICustomerManager>().FindAll();
//            gridCustomers.DataBind();
        }

        private void PreDataBind()
        {
//            rblSex.DataSource = EnumUtils.GetEnumDataSource<SexType>();
//            rblSex.DataTextField = "Key";
//            rblSex.DataValueField = "Value";
//            rblSex.DataBind();
//
//            ddlRole.DataSource = EnumUtils.GetEnumDataSource<CustomerRole>();
//            ddlRole.DataTextField = "Key";
//            ddlRole.DataValueField = "Value";
//            ddlRole.DataBind();
        }

        protected void btnAddUser_Click(object sender, EventArgs e)
        {
//            Customer customer = new Customer();
//            customer.FirstName = tbFirstName.Text;
//            customer.LastName = tbLastName.Text;
//            customer.Email = tbEmail.Text;
//            customer.Passwrd = AccountUtils.CreateMD5PasswordHash(tbPasswrd.Text);
//            customer.Sex = (SexType)Enum.Parse(typeof(SexType), rblSex.SelectedValue);
//            customer.Birthday = DateTime.Parse(tbBirthday.Text);
//            customer.Role = (CustomerRole)Enum.Parse(typeof(CustomerRole), ddlRole.SelectedValue);
//            customer.Discount = Convert.ToInt32(tbDiscount.Text);
//            customer.Phone = tbPhone.Text;
//            customer.Note = tbNote.Text;
//            Locator.GetService<ICustomerManager>().Save(customer);
        }

        protected void btnTest_Click(object sender, EventArgs e)
        {
            string to = "olga@morlin.ru";
            Dictionary<string, object> ret = new Dictionary<string, object>();
//            ret["body"] = body;
//            ret["contact"] = contact;

            SendMailByTemplate mlInvite = new SendMailByTemplate("subject", "FooterTemplate", "", to, null, ret);
            mlInvite.Send();
            
           // MailUtils.Send("olga@morlin.ru", "olga@morlin.ru", "test", "test");
        }
    }
}
